package com.minhua.jijiehao2.base

import android.text.TextUtils
import cn.jpush.android.api.JPushInterface
import com.baidu.ocr.sdk.OCR
import com.baidu.ocr.sdk.OnResultListener
import com.baidu.ocr.sdk.exception.OCRError
import com.baidu.ocr.sdk.model.AccessToken
import com.minhua.jijiehao2.constants.DefineKey
import com.minhua.jijiehao2.utils.SPUtils
import com.minhua.jijiehao2.utils.T
import com.mob.MobApplication


/**
 * @author moo
 * @date 2017/11/3.
 * @describe
 */

class BaseApplication : MobApplication() {

    companion object {
        var APP: BaseApplication? = null
    }


    override fun onCreate() {
        super.onCreate()
        APP = this
        SPUtils.init(this)
        T.init(this)
        SPUtils.init(this)
        T.init(this)

        JPushInterface.setDebugMode(true)
        JPushInterface.init(this)
        val userId = SPUtils.get(DefineKey.USER_ID, "") as String
        if (!TextUtils.isEmpty(userId)) {
            JPushInterface.setAlias(this, 0, userId)
        }

        OCR.getInstance().initAccessToken(object : OnResultListener<AccessToken> {
            override fun onResult(result: AccessToken) {
                // 调用成功，返回AccessToken对象
                val token = result.accessToken
                SPUtils.put(DefineKey.BAIDU_TOKEN, token)
            }

            override fun onError(error: OCRError) {
                // 调用失败，返回OCRError子类SDKError对象
            }
        }, applicationContext)
    }

}
